<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-05-07
 * Time: 9:26
 */
namespace app\Logic;

use App\Http\Controllers\ResponseJsonTrait;
use Illuminate\Http\Request;

class Logic
{
    public static $instance;

    protected static $uid;

    protected static $token;

    public static $error = array();

    public static $code = 'ERROR';

    public static $data;

    public $officialInstance;

    public function __construct()
    {
        $data = requestData();
        $this->officialInstance = officialInstance(
            WxUserLogic::first(['token'=>$data['token']])->appid
        );
    }


    public static function requestData()
    {
        return requestData();
    }

    public static function getUid()
    {
        if(self::$uid) return self::$uid;
        self::$uid = MemberLogic::getUid();

        return self::$uid;
    }

    public static function getToken()
    {
        if(self::$token) return self::$token;
        $data = self::requestData();
        self::$token = isset($data['token']) ? $data['token'] : '';

        return self::$token;
    }

    public static function getInstance()
    {
        if(self::$instance) return self::$instance;

        self::$instance = new static(app('request'));

        return self::$instance;
    }
}